﻿Imports System.Runtime.InteropServices

Public Class FrmMain

	<DllImport("dwmapi.dll", CharSet:=CharSet.Auto)> _
	Public Shared Sub DwmExtendFrameIntoClientArea(ByVal hWnd As System.IntPtr, ByRef pMargins As Margins)
	End Sub

	<DllImport("dwmapi.dll", CharSet:=CharSet.Auto)> _
	Public Shared Sub DwmIsCompositionEnabled(ByRef IsIt As Boolean)
	End Sub

	Public Shared SPI_SETDESKTOPWALLPAPER As Integer = 20
	Public Shared SPIF_UPDATEINIFILE As Integer = 1
	Public Shared SPIF_SENDWININICHANGE As Integer = 2

	<DllImport("User32.dll", CharSet:=CharSet.Auto)> _
	Public Shared Sub SystemParametersInfo(ByVal action As Integer, ByVal iparam As Integer, ByVal vparam As String, ByVal opt As Integer)
	End Sub

	Dim PopupList As New ContextMenuStrip With {.Renderer = New FirefoxRenderer}
	Dim EditList As New ContextMenuStrip With {.Renderer = New FirefoxRenderer}
	Dim PopupListItem As New ContextMenuStrip With {.Renderer = New FirefoxRenderer}
	Dim PopupPicture As New ContextMenuStrip With {.Renderer = New FirefoxRenderer}
	Dim EditListItem As New ContextMenuStrip With {.Renderer = New FirefoxRenderer}
	Dim PopupAlbums As New ContextMenuStrip With {.Renderer = New FirefoxRenderer}
	Dim EditAlbums As New ContextMenuStrip With {.Renderer = New FirefoxRenderer}

   Dim WithEvents Timer As New Timer With {.Interval = 30000}

   Dim Albums As ExpandablePanel.Box
   Dim Timeline As ExpandablePanel.Box

   Sub New()
      InitializeComponent()
      Application.EnableVisualStyles()
      Albums = Contents.AddBox("Albümler")
      Timeline = Contents.AddBox("Kronolojik")
      ToolStrip.Renderer = New FirefoxRenderer
		SetImages(BtnAll.DropDownItems)
      SetImages(ToolStrip.Items)
      For Each Item As ToolStripButton In From m In ToolStrip.Items Where TypeOf m Is ToolStripButton
         If Not Item.Image Is Nothing Then Item.Image = Item.Image.Resize(16, 16)
      Next
		List.AllowDrop = True
		List.BorderStyle = BorderStyle.None
      'List.Columns.Add("Ad", 150, HorizontalAlignment.Left)
      'List.Columns.Add("Tarih", 150, HorizontalAlignment.Center)
		Dim StdEnd As String = ",-,albums,-,view,group,layout,-,exit"
		'Dim StdEnd As String = ",-,exit"
      MnuView.DropDown = New ContextMenuStrip
      MnuView.DropDown.Renderer = New FirefoxRenderer
      MnuTools.DropDown = New ContextMenuStrip
      MnuTools.DropDown.Renderer = New FirefoxRenderer
      PrepareMenu(MnuTools.DropDown, "batch,settings")
      PrepareMenu(MnuView.DropDown, "view5,view4,view3,view2,-,view1,view0")
		PrepareMenu(EditList, "addalbum,add" & StdEnd)
      PrepareMenu(PopupList, "view,group,layout,background,-,paste,-,selectall", False)
      'PrepareMenu(EditList, "addalbum,add,-,cut,copy,paste,-,selectall" & StdEnd)
      'PrepareMenu(PopupList, "addalbum,add,-,view,group,layout,background,-,paste,-,selectall", False)
		PrepareMenu(EditListItem, "addalbum,add,-,open,save,wallpaper,-,cut,copy,paste,-,selectall,-,delete,rename,-,properties" & StdEnd)
		PrepareMenu(PopupListItem, "*open,-,save,wallpaper,-,cut,copy,paste,-,delete,rename,-,properties", False)
      'PrepareMenu(PopupPicture, "prev,next,-,edit,mark,-,rotate,save,wallpaper,-,cut,copy,-,delete,rename,props", False)
		'PrepareMenu(EditTree, "addalbum,add,-,expandall,-,save,-,paste,selectall" & StdEnd)
		PrepareMenu(PopupAlbums, "editalbum,deletealbum", False)
      'PrepareMenu(EditTreeItem, "addalbum,add,-,expand,collapse,-,save,-,cut,copy,paste,-,selectall,-,delete,rename,-,props" & StdEnd)
      'PrepareMenu(PopupTreeItem, "*expand,*collapse,-,icon,-,addalbum,add,-,save,-,cut,copy,paste,-,delete,rename,props", False)
		ImageSize = 3
		Explorer.Dock = DockStyle.Fill
		Picture.Dock = DockStyle.Fill
		Explorer.BringToFront()
      AddHandler List.GotFocus, AddressOf SetMenus
      Timer.Start()
      Albums.Expanded = True
      Timeline.Expanded = True
	End Sub

	Protected Overrides Sub OnLoad(ByVal e As System.EventArgs)
		MyBase.OnLoad(e)
		Studio.Open()
		For Each d In (From f In Studio.Files Select y = Mid(f.Datetime, 1, 4) Order By y).Distinct
			Timeline.AddLine(d, d, My.Resources.calendar)
		Next
		For Each Album In Studio.Albums
			Albums.AddLine(Album.Name, Album.Name, My.Resources.album)
		Next
		For Each Album In Studio.Albums
			Album.Open(Album.Name)
			Albums.Lines(Album.Name).Count = Album.Count
		Next
	End Sub

	Sub SetAero()
		Dim Inset As New Margins ' With {.Top = NavBar.Height}
		Dim IsAeroEnabled As Boolean = False
		DwmIsCompositionEnabled(IsAeroEnabled)
		If IsAeroEnabled Then DwmExtendFrameIntoClientArea(Me.Handle, Inset)
	End Sub

	Sub ApplySettings()
		If Settings.Background Like "bg*" Then
			List.BackgroundImage = My.Resources.ResourceManager.GetObject(Settings.Background)
			Picture.BackgroundImage = My.Resources.ResourceManager.GetObject(Settings.Background)
			Picture.BackgroundImageLayout = ImageLayout.Tile
		ElseIf Settings.Background > "" Then
			List.BackgroundImage = Nothing
			List.BackColor = Color.FromArgb(Settings.Background)
			Picture.BackgroundImage = Nothing
			Picture.BackColor = Color.FromArgb(Settings.Background)
			List.BackColor = SystemColors.ButtonFace
		End If
	End Sub

	Sub SetMenuEnabled(ByVal Name As String, ByVal Value As Boolean)
		For Each Item In (From m In AllCommands Where m.Tag = Name)
			Item.Enabled = Value
		Next
	End Sub

	Sub SetMenuVisible(ByVal Name As String, ByVal Value As Boolean)
		For Each Item In (From m In AllCommands Where m.Tag = Name)
			Item.Visible = Value
		Next
	End Sub

	Dim WithEvents SelectionTimer As New Timer With {.Interval = 50}

	Sub SetMenus()
		Dim SingleItem As Boolean = List.SelectedIndices.Count = 1
		Dim MultiItem As Boolean = List.SelectedIndices.Count > 1
		Dim HasSelection As Boolean = List.SelectedIndices.Count > 0
		SetMenuEnabled("cut", HasSelection)
		SetMenuEnabled("copy", HasSelection)
		SetMenuEnabled("delete", HasSelection)
		SetMenuVisible("open", SingleItem)
		'SetMenuVisible("rename", SelectedCount = 1)
		'SetMenuVisible("props", SelectedCount = 1)
		'SetMenuVisible("edit", SingleItem AndAlso HasPhotos)
		'SetMenuVisible("wallpaper", SingleItem AndAlso HasPhotos)
		'SetMenuVisible("thumb", SingleItem AndAlso HasVideos)
		'SetMenuVisible("rate", False)
		'SetMenuVisible("tag", False)
		'SetMenuVisible("icon", HasAlbums OrElse Tree Is ActiveControl)
		'SetMenuVisible("rotate", HasPhotos)
		If List Is ActiveControl Then
			If Not HasSelection Then
				List.ContextMenuStrip = PopupList
				BtnEdit.DropDown = EditList
			Else
				List.ContextMenuStrip = PopupListItem
				BtnEdit.DropDown = EditListItem
				'Picture.ContextMenuStrip = PopupPicture
			End If
		ElseIf Contents Is ActiveControl Then
			If Contents.SelectedItem Is Nothing Then Return
			If Contents.SelectedItem.Box Is Albums Then
				Contents.ContextMenuStrip = PopupAlbums
			End If
		End If
	End Sub

	Sub PrepareMenu(ByVal MenuStrip As ContextMenuStrip, ByVal Items As String, Optional ByVal ShowShortcuts As Boolean = True)
		AddHandler MenuStrip.Opening, AddressOf MenuOpening
		For Each Item In Items.Split(",")
			Dim Bold As Boolean = False
			If Item.Contains("*") Then
				Item = Item.Replace("*", "")
				Bold = True
			End If
			If Item = "-" Then
				MenuStrip.Items.Add("-")
			Else
				Dim c = Commands(Item)
				Dim Menu As New ToolStripMenuItem With {.Text = c.Text, .ShortcutKeys = c.ShortcutKeys, .Tag = c.Tag, .Image = c.Image, .ShowShortcutKeys = ShowShortcuts, .ShortcutKeyDisplayString = c.ShortcutKeyDisplayString}
				MenuStrip.Items.Add(Menu)
				If Bold Then Menu.Font = New Font(Menu.Font, FontStyle.Bold)
				AllCommands.Add(Menu)
				AddHandler Menu.Click, AddressOf Perform
				If c.HasDropDownItems Then AddSubItems(Menu, c)
			End If
		Next
	End Sub

	Sub MenuOpening(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs)
		'SetMenuEnabled("paste", Studio.Clipboard.Count > 0)
	End Sub

	Sub AddSubItems(ByVal ParentMenu As ToolStripMenuItem, ByVal SrcMenu As ToolStripMenuItem)
		For Each sm In SrcMenu.DropDownItems
			If TypeOf sm Is ToolStripSeparator Then
				ParentMenu.DropDownItems.Add("-")
			Else
				Dim Menu As New ToolStripMenuItem With {.Text = sm.Text, .ShortcutKeys = sm.ShortcutKeys, .Tag = sm.Tag, .Image = sm.Image}
				ParentMenu.DropDownItems.Add(Menu)
				AllCommands.Add(Menu)
				AddHandler Menu.Click, AddressOf Perform
				If sm.HasDropDownItems Then AddSubItems(Menu, sm)
			End If
		Next
	End Sub

	Dim Commands As New SortedList(Of String, ToolStripMenuItem)
	Dim AllCommands As New List(Of ToolStripItem)
	Sub SetImages(ByVal Items As ToolStripItemCollection)
		For Each Item As ToolStripItem In From m In Items Where TypeOf m Is ToolStripItem
			If Item.Tag <> "" Then
				If TypeOf Item Is ToolStripMenuItem And Not Commands.ContainsKey(Item.Tag) Then Commands.Add(Item.Tag, Item)
				Dim R = My.Resources.ResourceManager.GetObject(Item.Tag)
				If Not R Is Nothing Then Item.Image = CType(R, Image).Resize(16, 16)
				AllCommands.Add(Item)
			End If
			If TypeOf Item Is ToolStripDropDownItem Then SetImages(CType(Item, ToolStripDropDownItem).DropDownItems)
		Next
	End Sub

	Private Sub Perform(ByVal sender As System.Object, ByVal e As System.EventArgs)
		Perform(sender.Tag)
	End Sub

	Private Sub Perform(ByVal key As String)
		Select Case key
			Case "addalbum"
				Dim Form As New FrmAlbum
				If Not Form.ShowDialog = Windows.Forms.DialogResult.OK Then Return
				Dim Album As New Album()
				Studio.Albums.Add(Form.TxtName.Text, Album)
				Album.Open(Form.TxtName.Text)
				Studio.Albums.Save()
				Albums.AddLine(Form.TxtName.Text, Form.TxtName.Text, My.Resources.album)
			Case "add"
				AddPhotos()
			Case "open"
				Picture.File = List.SelectedItems(0).Name
				Picture.BringToFront()
				BtnBack2.Visible = True
				SepBack2.Visible = True
				'If TypeOf List.SelectedItem Is Video Then
				'   CType(List.SelectedItem, Video).Open()
				'Else
				'Canvas.
				'GotoNode(SelectedFiles(0), "")
				'End If
			Case "edit"
				'Process.Start(MainFolder & List.SelectedItem.Title)
			Case "thumb"
				'Dim Video As Video = SelectedFiles(0)
				'If My.Settings.ffmpeg <> "" AndAlso Not My.Settings.ffmpeg.Exists Then My.Settings.ffmpeg = ""
				'If My.Settings.ffmpeg = "" Then
				'	Dim a = My.Computer.FileSystem.SpecialDirectories.ProgramFiles.Find("ffmpeg.exe")
				'	If Not a.Any Then Warning("Sisteminizde ffmpeg uygulaması bulunamadı.") : Exit Sub
				'	My.Settings.ffmpeg = a.First
				'End If
				'Dim Form As New FrmThumb
				'Form.Video = Video
				'If Not Form.ShowDialog() = Windows.Forms.DialogResult.OK Then Exit Sub
				'Video.SetThumb(My.Computer.FileSystem.SpecialDirectories.Temp & "\" & Video.Title & "1.png")
				'Video.Redraw()
			Case "wallpaper"
				'SystemParametersInfo(SPI_SETDESKTOPWALLPAPER, 0, SelectedFiles(0).Source, (SPIF_UPDATEINIFILE Or SPIF_SENDWININICHANGE))
			Case "cut"
				'Studio.Clipboard.Clear()
				'For Each Item In SelectedFiles
				'Studio.Clipboard.Add(Item)
				'Next
				List.Invalidate()
			Case "back"
				Picture.SendToBack()
				List.Focus()
				SepBack2.Visible = False
				BtnBack2.Visible = False
			Case "paste"
				'For Each File In (From f In Studio.Files.Values Where f.IsCut)
				'	File.Album = Studio.Current
				'	If TypeOf File Is Album Then
				'		Dim Node As TreeNode = GetNode(File)
				'		Node.Parent.Nodes.Remove(Node)
				'		GetNode(File.Album).Nodes.Add(Node)
				'	End If
				'Next
				'Studio.Save()
				'Populate()
				'For Each File In Studio.Clipboard
				'	File.Selected = True
				'Next
				'Studio.Clipboard.Clear()
			Case "delete"
				If List.SelectedItems.Count = 0 Then Return
				If Contents.SelectedItem.Box Is Albums Then
					If Not Confirm("Seçili öğeleri albümden çıkarmak istediğinize emin misiniz?") Then Return
					Dim Album = Studio.Albums(Contents.SelectedItem.Name)
					For Each Item As ListViewItem In List.SelectedItems
						Album.Delete(Item.Name)
					Next
					Album.Save()
					For Each Item In List.SelectedItems
						List.Remove(Item.Name)
					Next
					Contents.SelectedItem.Count = Album.Count
					Details.Invalidate()
				End If
				'If SelectedCount = 0 Then Exit Sub
				'If Not Confirm("Bu dosyaları silmek istediğinizden emin misiniz?") Then Exit Sub
				'For Each File In SelectedFiles
				'	File.Delete(List, Tree)
				'Next
				'Studio.Save()
			Case "selectall"
				List.SelectAll()
			Case "properties"
				Dim Form As New FrmInfo
				Form.Open(SelectedItem)
				Form.ShowDialog()
			Case "editalbum"
				Dim Form As New FrmAlbum(Studio.Albums(Contents.SelectedItem.Text))
				If Not Form.ShowDialog = Windows.Forms.DialogResult.OK Then Return
				'Dim Album As New Album(Form.TxtName.Text)
				'Studio.Albums.Add(Album.Name, Album)
				'Studio.Albums.Save()
				'Albums.AddLine(Form.TxtName.Text, Form.TxtName.Text, My.Resources.album)
			Case "deletealbum"
				If Not Confirm("Albümü silmek istediğinizden emin misiniz?") Then Return
				Studio.Albums.Delete(Contents.SelectedItem.Text)
				Albums.Remove(Contents.SelectedItem.Text)
			Case "rename"
				'If ActiveFile Is Nothing Then Exit Sub
				'Dim File = ActiveFile
				'Dim Text As String = InputBox("Yeni ad:", "Adını Değiştir", File.Title)
				'If Text = "" Then Exit Sub
				'Studio.Rename(File, Text)
				'If Not List.Items.Contains(File.Item) Then Exit Sub
				'File.Populate(File.Item)
			Case "view0", "view1", "view2", "view3", "view4", "view5"
				ImageSize = Strings.Right(key, 1)
			Case "zoomin", "zoomout"
				ImageSize = ImageSize + If(key = "zoomin", 1, -1)
			Case "layoutdetails"
				Details.Visible = Not Details.Visible
			Case "group0", "group2", "group3", "group4"
				Grouping = Mid(key, 6)
				ApplyGrouping()
			Case "settings", "background"
				Dim Form As New Settings
				If Not Form.ShowDialog() = Windows.Forms.DialogResult.OK Then Exit Sub
				ApplySettings()
			Case "exit"
				Close()
			Case "closepic"
				Perform("back")
			Case "prev"
				Dim i = List.SelectedItems(0).Index
				If i = 0 Then Return
				List.SelectedItems.Clear()
				List.Items(i - 1).Selected = True
				Perform("open")
			Case "next"
				Dim i = List.SelectedItems(0).Index
				If i = List.Items.Count - 1 Then Return
				List.SelectedItems.Clear()
				List.Items(i + 1).Selected = True
				Perform("open")
			Case "rotate1", "rotate2", "rotate3"
			Case "birthday", "wedding", "family", "dinner", "vacation", "beach", "classic", "nature"
			Case "batch"
				FrmBatch.ShowDialog()
				List.Invalidate()
				'Picture.FixRect()
			Case "full"
				'Picture.ToggleFullsize()
			Case "mark"
				'For Each Item In SelectedFiles
				'	If Studio.Marked.Contains(Item) Then
				'		Studio.Marked.Remove(Item)
				'		Item.Redraw()
				'	Else
				'		Studio.Marked.Add(Item)
				'		Item.Redraw()
				'	End If
				'Next
			Case "save"
				Dim Dlg As New FolderBrowserDialog
				If Dlg.ShowDialog <> Windows.Forms.DialogResult.OK Then Exit Sub
				'For Each Item As Photo In SelectedFiles
				'Item.Save(Dlg.SelectedPath)
				'Next
		End Select
	End Sub

	ReadOnly Property SelectedItem As String
		Get
			Return List.SelectedItems(0).Name
		End Get
	End Property

	Dim Grouping As Integer = 0
	Sub ApplyGrouping()
		List.BeginUpdate()
		List.Groups.Clear()
		If Grouping <> "0" Then
			Dim Groups As New SortedList(Of String, ListViewGroup)
			For Each Item In (From i In List.Items Let Data = i.SubItems(Grouping).Text Where Data <> "" Select Data).Distinct
				Groups.Add(Item, New ListViewGroup(Trim(Item), Trim(Item)))
			Next
			List.Groups.AddRange(Groups.Values.ToArray)
			For Each Result In From i In List.Items Select i, g = i.SubItems(Grouping).Text Where g <> ""
				Result.i.Group = Groups(Result.g)
			Next
			List.ShowGroups = True
		End If
		List.EndUpdate()
	End Sub

	Dim m_ImageSize As Integer
	Property ImageSize As Integer
		Get
			Return m_ImageSize
		End Get
		Set(ByVal Value As Integer)
			m_ImageSize = Value
			BtnZoomin.Enabled = m_ImageSize < 5
			BtnZoomout.Enabled = m_ImageSize > 0
			If Value = 0 Then
				'List.OwnerDraw = False
				'List.View = View.Details
			ElseIf Value = 1 Then
				'List.OwnerDraw = False
				'List.View = View.List
			Else
				'List.OwnerDraw = True
				Dim Size = Choose(Value, 1, 48, 64, 128, 256)
				List.ImageSize = New Size(Size, Size)
			End If
		End Set
	End Property


	Private Sub List_Activate(ByVal sender As Object, ByVal e As System.EventArgs) Handles List.Activate
		Perform("open")
	End Sub

	Protected Overrides Function ProcessCmdKey(ByRef msg As System.Windows.Forms.Message, ByVal keyData As System.Windows.Forms.Keys) As Boolean
		If BtnBack2.Visible Then
			If keyData = Keys.Left Then Perform("prev") : Return True
			If keyData = Keys.Right Then Perform("next") : Return True
		End If
		If keyData = Keys.Back Then Perform("back") : Return True
		If keyData = Keys.Escape Then Perform("back") : Return True
		Return MyBase.ProcessCmdKey(msg, keyData)
	End Function

	'Private Sub Picture_ButtonClicked(ByVal Key As String) Handles Picture.ButtonClicked
	'   Perform(Key)
	'End Sub

	Private Sub Picture_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Picture.Click
		If Picture.AutoSize Then Perform("next")
	End Sub

#Region " Drag & Drop "

	Private Sub List_ItemDrag(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ItemDragEventArgs) Handles List.ItemDrag
		List.DoDragDrop(New DataObject("System.Windows.Forms.ListView.SelectedListViewItemCollection", List.SelectedItems), DragDropEffects.Move)
	End Sub

	Private Sub Contents_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles Contents.DragDrop
		Dim Target = Contents.HitTest(Contents.PointToClient(New Point(e.X, e.Y)))
		If Target Is Nothing Then Exit Sub
		If e.Data.GetDataPresent("System.Windows.Forms.ListView.SelectedListViewItemCollection") Then
			Dim Album = Studio.Albums(Target.Name)
			For Each Item In e.Data.GetData("System.Windows.Forms.ListView.SelectedListViewItemCollection")
				Album.Add(Item.Name)
			Next
			Album.Save()
			Target.Count = Album.Count
			Details.Invalidate()
		End If
		Contents.DropTarget = Nothing
	End Sub

	Private Sub Contents_DragEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles Contents.DragEnter, Contents.DragOver
		Dim Target As ExpandablePanel.Line = Contents.HitTest(Contents.PointToClient(New Point(e.X, e.Y)))
		If Target Is Nothing Then Contents.DropTarget = Nothing : e.Effect = DragDropEffects.None : Return
		If e.Data.GetDataPresent("System.Windows.Forms.ListView.SelectedListViewItemCollection") Then
			If Target.Box Is Albums Then Contents.DropTarget = Target : e.Effect = DragDropEffects.All
		End If
	End Sub

	Private Sub Contents_DragLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles Contents.DragLeave
		Contents.DropTarget = Nothing
	End Sub

#End Region

	Sub AddPhotos(Optional ByVal Opt As Integer = 0)
		'Dim Form As New FrmAdd
		'Form.Opt = Opt
		'If Form.ShowDialog <> Windows.Forms.DialogResult.OK Then Exit Sub
		'Populate()
	End Sub

	Private Sub Details_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Details.Paint
		Dim R As Rectangle = Details.ClientRectangle
		'R.Offset(0, 2)
		R.Width = R.Height
		R.Inflate(-4, -4)
		e.Graphics.SmoothingMode = Drawing2D.SmoothingMode.HighQuality
		e.Graphics.PixelOffsetMode = Drawing2D.PixelOffsetMode.HighQuality
		e.Graphics.InterpolationMode = Drawing2D.InterpolationMode.HighQualityBicubic
		If Contents.SelectedItem Is Nothing Then Return
		If Contents.SelectedItem.Box Is Albums Then
			e.Graphics.DrawImage(My.Resources.albumb, R)
			R.Offset(R.Width, 0) : R.Width = Details.Width - R.Left
			R.Height *= 3 / 5
			Dim Text = Contents.SelectedItem.Text
			e.Graphics.DrawText(Text, New Font("segoe ui", 12, FontStyle.Regular), R, Color.DarkSlateGray, TextFormatFlags.VerticalCenter)
			Dim t = Studio.Albums(Contents.SelectedItem.Text).Date
			R.Offset(0, R.Height)
			R.Height *= 2 / 5
			e.Graphics.DrawText(t.ToString("dd/MM/yyyy"), New Font("segoe ui", 9, FontStyle.Regular), R, Color.Black, TextFormatFlags.VerticalCenter)
			'ElseIf List.SelectedItems.Count > 1 Then
			'	e.Graphics.DrawImage(My.Resources.album, R)
			'	R.Offset(R.Width, 0) : R.Width = Details.Width - R.Left
			'	Dim AlbumCount As Integer = (From f In List.SelectedItems Where TypeOf f Is Album).Count
			'	Dim PhotoCount As Integer = (From f In List.SelectedItems Where TypeOf f Is Photo).Count
			'	Dim Text As String = ""
			'	If AlbumCount > 0 Then Text &= ", " & AlbumCount & " adet albüm"
			'	If PhotoCount > 0 Then Text &= ", " & PhotoCount & " adet fotoğraf"
			'	If Text = "" Then Text = "Hiç dosya seçilmemiş" Else Text = Mid(Text, 3) & " seçili"
			'	TextRenderer.DrawText(e.Graphics, Text, Font, R, Color.Black, Color.Transparent, TextFormatFlags.VerticalCenter)
			'Else
			'If TypeOf List.SelectedItem Is Album Then
			'e.Graphics.DrawImage(My.Resources.album, R)
			'R.Offset(R.Width, 0) : R.Width = Details.Width - R.Left
			'Dim AlbumCount As Integer = (From f In Studio.Files.Values Where f.Album Is List.SelectedItem And TypeOf f Is Album).Count
			'Dim PhotoCount As Integer = (From f In Studio.Files.Values Where f.Album Is List.SelectedItem And TypeOf f Is Photo).Count
			'Dim Text As String = ""
			'If AlbumCount > 0 Then Text &= ", " & AlbumCount & " adet alt albüm"
			'If PhotoCount > 0 Then Text &= ", " & PhotoCount & " adet fotoğraf"
			'Text = Mid(Text, 3)
			'If Text = "" Then Text = "boş albüm"
			'Text = List.SelectedItem.Title & ", " & Text
			'TextRenderer.DrawText(e.Graphics, Text, Font, R, Color.Black, Color.Transparent, TextFormatFlags.VerticalCenter)
			'ElseIf TypeOf List.SelectedItem Is Photo Then
			'CType(List.SelectedItem, Photo).Fill(e.Graphics, R)
			'R.Offset(R.Width, 0) : R.Width = Details.Width - R.Left
			''Dim Photo As Photo = List.SelectedItem
			'Dim Text As String = Photo.Title
			'If Photo.DateTaken > "" Then Text &= ", " & Trim(Photo.DateTaken) & " tarihli fotoğraf"
			'TextRenderer.DrawText(e.Graphics, Text, Font, R, Color.Black, Color.Transparent, TextFormatFlags.VerticalCenter)
			'End If
		End If
	End Sub

	Private Sub ToolStrip_ItemClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ToolStripItemClickedEventArgs) Handles ToolStrip.ItemClicked
		Perform(e.ClickedItem.Tag)
	End Sub

	Private Sub List_PaintItem(ByVal sender As Object, ByVal G As System.Drawing.Graphics, ByVal Item As System.Windows.Forms.ListViewItem, ByVal R As Rectangle) Handles List.PaintItem
		If List.Updating Then Exit Sub
		Images.DrawThumb(G, R, Item.Name, Item.Selected)
	End Sub

	'Private Sub Picture_Maximize() Handles Picture.Maximize
	'   WindowState = If(WindowState = FormWindowState.Maximized, FormWindowState.Normal, FormWindowState.Maximized)
	'End Sub

	'Private Sub List_ItemSelectionChanged(ByVal sender As Object, ByVal e As System.Windows.Forms.ListViewItemSelectionChangedEventArgs) Handles List.ItemSelectionChanged
	'   SelectionTimer.Stop()
	'   SelectionTimer.Start()
	'End Sub

	Private Sub SelectionTimer_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles SelectionTimer.Tick
		SetMenus()
	End Sub

	Private Sub List_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles List.KeyDown
		If e.KeyCode = Keys.Space Then
			Perform("mark")
		End If
	End Sub

	Private Sub ToolStrip_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles ToolStrip.Paint
		FirefoxRenderer.PaintBackground(e.Graphics, sender.ClientRectangle)
	End Sub

	Private Sub Contents_SelectedItemChanged(ByVal sender As Object, ByVal Line As ExpandablePanel.Line) Handles Contents.SelectedItemChanged
		If Line.Box Is Timeline Then
			ShowList((From f In Studio.Files Where Mid(f.Datetime, 1, Len(Line.Name)) = Line.Name Order By f.Datetime).ToList)
		ElseIf Line.Box Is Albums Then
         ShowList((From n In Studio.Albums(Line.Text).Files Select f = Studio.Files(n.Name)).ToList)
		End If
		Details.Invalidate()
	End Sub

	Sub ShowAllFiles()
		ShowList((From f In Studio.Files Order By f.Datetime).ToList)
	End Sub

	Sub ShowList(ByVal Listx As List(Of File))
		List.BeginUpdate()
		List.Items.Clear()
		For Each Row In (From f In Listx Order By f.Datetime)
			Dim Item As New ListViewItem
			Item.Name = Row.Name
			Item.Text = Row.Name
			Item.SubItems.Add(Mid(Row.Datetime, 1, 10))
			Item.SubItems.Add(Mid(Row.Datetime, 1, 10))
			Item.SubItems.Add(Mid(Row.Datetime, 1, 7))
			Item.SubItems.Add(Mid(Row.Datetime, 1, 4))
			List.Items.Add(Item)
		Next
		List.EndUpdate()
		Perform("back")
		'Me.List.BeginUpdate()
		'Me.List.VirtualListSize = Items.Count
		'Me.List.EndUpdate()
	End Sub

   'Private Sub List_PaintItem(ByVal g As System.Drawing.Graphics, ByVal Item As ListViewItem) Handles List.PaintItem
   '   Dim R = Item.Bounds
   '   R.Inflate(-2, -2)
   '   Studio.DrawThumb(g, R, Item.Name, Item.Selected)
   'End Sub

	Private Sub List_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles List.SelectedIndexChanged
		SetMenus()
	End Sub

	Private Sub Contents_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Contents.MouseDown
		SetMenus()
	End Sub
End Class

